/*
Copyright 2021 LuJun

Permission is hereby granted, free of charge, to any person obtaining a copy 
of this software and associated documentation files (the "Software"), to deal 
in the Software without restriction, including without limitation the rights 
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
copies of the Software, and to permit persons to whom the Software is furnished 
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in 
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { warn, error, EventTarget } from 'cc';
import { Macro } from './macro';

const TAG = 'lcc/core/base.ts';

/**
 * @zh
 * 版本号
 */
export const VERSION = '1.0.0';

/**
 * @zh
 * 默认定时器组
 */
export const DEFAULT_TIMER_GROUP = 'default';

/**
 * @zh
 * 默认HTTP协议路径
 */
export const DEFAULT_HTTP_PROTOCOL = 'protocol';

/**
 * @zh
 * 默认HTTP发送超时时间
 */
export const DEFAULT_HTTP_SEND_TIMEOUT = 5;

/**
 * 默认全局BGM音量
 */
export const DEFAULT_BGM_VOLUME = 0.5;

/**
 * 默认全局SE音量
 */
export const DEFAULT_SE_VOLUME = 0.5;

// ------------------------------ 事件

/**
 * @zh
 * 全局事件对象
 */
export const event = new EventTarget();

/**
 * @zh
 * 事件 - 异步完成
 */
export const EVENT_ASYNC_COMPLETE = '__ASYNC_COMPLETE__';

/**
 * @zh
 * 事件 - 包加载中
 */
export const EVENT_PACK_LOADING = '__PACK_LOADING__';

/**
 * @zh
 * 事件 - 包加载完成
 */
export const EVENT_PACK_LOADED = '__PACK_LOADED__';

/**
 * @zh
 * 事件 - 索引加载
 */
export const EVENT_INDEXES_LOAD = '__INDEXES_LOAD__';

/**
 * @zh
 * 事件 - 场景转换
 */
export const EVENT_SWITCH_SCENE = '__SWITCH_SCENE__';

/**
 * @zh
 * 事件 - 存档加载
 */
export const EVENT_ARCHIVE_LOAD = '__ARCHIVE_LOAD__';

/**
 * @zh
 * 事件 - 存档加载
 */
export const EVENT_ARCHIVE_SAVE = '__ARCHIVE_SAVE__';

/**
 * @zh
 * 事件 - 存档创建
 */
export const EVENT_ARCHIVE_CREATE = '__ARCHIVE_CREATE__';

/**
 * @zh
 * 事件 - 语言切换
 */
export const EVENT_LANGUAGE_SWITCH = '__LANGUAGE_SWITCH__';

/**
 * @zh
 * 事件 - UI界面打开
 */
export const EVENT_UI_OPENED = '__UI_OPENED__';

/**
 * @zh
 * 事件 - UI界面关闭
 */
export const EVENT_UI_CLOSED = '__UI_CLOSED__';

/**
 * @zh
 * 事件 - 网络线打开
 */
export const EVENT_NETLINE_ONOPEN = '__NETLINE_ONOPEN__';

/**
 * @zh
 * 事件 - 网络线关闭
 */
export const EVENT_NETLINE_ONCLOSE = '__NETLINE_ONCLOSE__';

/**
 * @zh
 * 事件 - 网络线错误
 */
export const EVENT_NETLINE_ONERROR = '__NETLINE_ONERROR__';

/**
 * @zh
 * 事件 - 网络线分发数据
 */
export const EVENT_NETLINE_DISPATCH = '__NETLINE_DISPATCH__';

// ------------------------------ 冲突

/**
 * @zh
 * 日志 - 冲突
 *
 * @param tag 标签
 * @param msg 消息
 *
 * @returns boolean 是否看作错误
 */
export function conflict(tag: string, msg: string) {
    if (Macro.CONFLICT_AS_ERROR) {
        error(tag, msg);
    } else {
        warn(tag, msg);
    }
    return Macro.CONFLICT_AS_ERROR;
}
